﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Default.Master" AutoEventWireup="true"
  CodeBehind="CustomerList.aspx.cs" Inherits="SaleManagement.Web.Pages.CustomerList" %>

<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <table width="100%" class="">
    <tr>
      <td class="search_header" colspan="7">
        Danh sách khách hàng
      </td>
    </tr>
    <tr>
      <td style="height: 19px">
        <asp:Literal ID="Literal5" runat="server" Text="Mã KH"></asp:Literal>
        :
      </td>
      <td style="height: 19px">
        <dxe:ASPxTextBox ID="txtSearchCode" runat="server" Width="120px" ClientInstanceName="txtSearchCode"
          CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
          <ValidationSettings>
            <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
            <ErrorFrameStyle ImageSpacing="4px">
              <ErrorTextPaddings PaddingLeft="4px" />
            </ErrorFrameStyle>
          </ValidationSettings>
        </dxe:ASPxTextBox>
      </td>
      <td style="height: 19px">
      </td>
      <td style="height: 19px">
        <asp:Literal ID="Literal6" runat="server" Text="Tên KH"></asp:Literal>
        :
      </td>
      <td style="height: 19px">
        <div style="float: left;">
        </div>
        <dxe:ASPxTextBox ID="txtSearchName" runat="server" Width="120px" ClientInstanceName="txtSearchName"
          CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
          <ValidationSettings>
            <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
            <ErrorFrameStyle ImageSpacing="4px">
              <ErrorTextPaddings PaddingLeft="4px" />
            </ErrorFrameStyle>
          </ValidationSettings>
        </dxe:ASPxTextBox>
      </td>
      <td style="height: 19px">
        <asp:Literal ID="Literal2" runat="server" Text="Số điện thoại"></asp:Literal>
        :
      </td>
      <td style="height: 19px">
        <div style="float: left;">
        </div>
        <dxe:ASPxTextBox ID="txtSearchPhone" runat="server" Width="120px" ClientInstanceName="txtSearchPhone"
          CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
          <ValidationSettings>
            <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
            <ErrorFrameStyle ImageSpacing="4px">
              <ErrorTextPaddings PaddingLeft="4px" />
            </ErrorFrameStyle>
          </ValidationSettings>
        </dxe:ASPxTextBox>
      </td>
      <td>
        <dxe:ASPxButton ID="ASPxButton1" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
          CssPostfix="Aqua" Text="Tìm kiếm" ClientInstanceName="btnSearch">
          <ClientSideEvents Click="function(s,e){onbtnSearch(s,e);e.processOnServer=false;}" />
        </dxe:ASPxButton>
      </td>
    </tr>
  </table>
  <div>
    <dxwgv:ASPxGridView ID="gvCustomer" runat="server" Width="100%" AutoGenerateColumns="False"
      CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" KeyFieldName="Id"
      OnCustomCallback="gvCustomer_CustomCallback" OnCustomJSProperties="gvCustomer_CustomJSProperties"
      OnPageIndexChanged="gvCustomer_PageIndexChanged" ClientInstanceName="gvCustomer"
      OnHtmlDataCellPrepared="gvCustomer_HtmlDataCellPrepared">
      <SettingsBehavior AllowDragDrop="false" AllowSort="false" AllowGroup="False" />
      <Columns>
        <dxwgv:GridViewDataTextColumn Name="Command" VisibleIndex="0" Width="7%">
          <DataItemTemplate>
            <img src="../Images/delete.png" onclick="onDelete('<%#Eval("Id") %>')" style="cursor: pointer"
              alt="" />
            <img src="../Images/edit.png" runat="server" id="imgEdit" style="cursor: pointer;"
              alt="" />
          </DataItemTemplate>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Width="15%" FieldName="CustomerNo" VisibleIndex="1"
          Caption="Mã khách hàng">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Width="15%" FieldName="Name" VisibleIndex="1" Caption="Tên khách hàng">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="Phone" Caption="Điện thoại" VisibleIndex="2">
          <HeaderStyle HorizontalAlign="Center" />
          <CellStyle HorizontalAlign="Right">
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="Fax" Caption="Fax" VisibleIndex="3">
          <HeaderStyle HorizontalAlign="Center" />
          <CellStyle HorizontalAlign="Right">
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataMemoColumn Width="20%" FieldName="Address" VisibleIndex="5" Caption="Địa chỉ">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataMemoColumn>
        <dxwgv:GridViewDataTextColumn Width="15%" FieldName="Email" VisibleIndex="6" Caption="Email">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataTextColumn>
      </Columns>
      <Images ImageFolder="~/App_Themes/Aqua/{0}/">
        <HeaderSortDown Height="5px" Width="6px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortDown.png" />
        <CollapsedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvCollapsedButton.png" />
        <ExpandedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvExpandedButton.png" />
        <DetailCollapsedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvDetailCollapsedButton.png" />
        <DetailExpandedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvDetailExpandedButton.png" />
        <HeaderFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilter.png" Width="19px" />
        <HeaderActiveFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilterActive.png"
          Width="19px" />
        <HeaderSortUp Height="5px" Width="6px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortUp.png" />
        <FilterRowButton Height="13px" Width="13px" />
        <CustomizationWindowClose Width="18px" />
        <PopupEditFormWindowClose Width="18px" />
        <WindowResizer Height="13px" Width="12px" Url="~/App_Themes/Aqua/GridView/WindowResizer.png" />
        <FilterBuilderClose Width="18px" />
      </Images>
      <ClientSideEvents EndCallback="function(s, e) {
	ongvCustomer_EndCallback(s,e);
}" />
      <StylesEditors>
        <ProgressBar Height="25px">
        </ProgressBar>
      </StylesEditors>
      <ImagesEditors>
        <CalendarPrevYear Width="23px" />
        <CalendarPrevMonth Width="19px" />
        <CalendarNextMonth Width="19px" />
        <CalendarNextYear Width="23px" />
        <CalendarFastNavPrevYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNPrevYear.png" />
        <CalendarFastNavNextYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNNextYear.png" />
        <DropDownEditDropDown Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" />
        <SpinEditIncrement Height="6px" Url="~/App_Themes/Aqua/Editors/edtSpinEditIncrementImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditIncrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png" />
        <SpinEditDecrement Height="7px" Url="~/App_Themes/Aqua/Editors/edtSpinEditDecrementImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditDecrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png" />
        <SpinEditLargeIncrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png" />
        <SpinEditLargeDecrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png" />
      </ImagesEditors>
      <Styles CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
      </Styles>
      <SettingsLoadingPanel Text="" />
      <SettingsPager>
        <AllButton>
          <Image Height="19px" Width="28px" />
        </AllButton>
        <FirstPageButton>
          <Image Height="19px" Width="23px" />
        </FirstPageButton>
        <LastPageButton>
          <Image Height="19px" Width="23px" />
        </LastPageButton>
        <NextPageButton>
          <Image Height="19px" Width="19px" />
        </NextPageButton>
        <PrevPageButton>
          <Image Height="19px" Width="19px" />
        </PrevPageButton>
      </SettingsPager>
    </dxwgv:ASPxGridView>
  </div>
  <div style="padding-top: 5px;">
    <dxe:ASPxButton ID="btnAdd" runat="server" Text="Thêm mới" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
      CssPostfix="Aqua" AutoPostBack="False">
      <Image Url="../Images/add.png" />
      <ClientSideEvents Click="function(s, e) {
	onAdd();e.processOnServer = false;
}" />
    </dxe:ASPxButton>
  </div>
  <div>
    <dxpc:ASPxPopupControl ID="pcAddCustomer" ClientInstanceName="pcAddCustomer" runat="server"
      CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" ImageFolder="~/App_Themes/Aqua/{0}/"
      Width="470px" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
      HeaderText="Thông tin khách hàng" CloseAction="CloseButton" Modal="True">
      <ContentStyle VerticalAlign="Top">
      </ContentStyle>
      <SizeGripImage Height="12px" Width="12px" />
      <ContentCollection>
        <dxpc:PopupControlContentControl>
          <div>
            <dxe:ASPxLabel ID="lblErrorMessage" ClientInstanceName="lblErrorMessage" runat="server"
              Font-Bold="True" ForeColor="#FF3300">
            </dxe:ASPxLabel>
          </div>
          <table>
            <tr>
              <td style="width: 120px">
                <asp:Label ID="Label1" runat="server" Text="Tên khách hàng"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtName" ClientInstanceName="txtName" runat="server" Width="170px"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label4" runat="server" Text="Điện thoại"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtPhone" ClientInstanceName="txtPhone" runat="server" Width="170px"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label3" runat="server" Text="Fax"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtFax" ClientInstanceName="txtFax" runat="server" Width="170px"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label5" runat="server" Text="Email"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtEmail" runat="server" ClientInstanceName="txtEmail" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="300px">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td style="padding-top: 4px;" valign="top">
                <asp:Label ID="Label2" runat="server" Text="Địa chỉ"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtAddress" runat="server" ClientInstanceName="txtAddress" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="300px">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
              </td>
              <td style="padding-top: 4px;">
                <div style="float: left;">
                  <dxe:ASPxButton ID="btnSave" runat="server" AutoPostBack="False" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                    CssPostfix="Aqua" Text="Lưu">
                    <Image Url="../Images/save.png" />
                    <ClientSideEvents Click="function(s, e) {
	                          onSave();
                        }" />
                  </dxe:ASPxButton>
                </div>
                <div style="float: left; padding-left: 3px;">
                  <dxe:ASPxButton ID="btnCancel" runat="server" AutoPostBack="False" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                    CssPostfix="Aqua" Text="Đóng">
                    <Image Url="../Images/cancel.png" />
                    <ClientSideEvents Click="function(s, e) {
	                            onCancel(); e.processOnServer = false;
                      }" />
                  </dxe:ASPxButton>
                </div>
              </td>
            </tr>
          </table>
        </dxpc:PopupControlContentControl>
      </ContentCollection>
      <CloseButtonImage Height="16px" Width="18px" />
      <HeaderStyle Font-Bold="True" ForeColor="#59A1EF" />
    </dxpc:ASPxPopupControl>
  </div>
  <div>
    <asp:HiddenField ID="hfCustomer" runat="server" />
  </div>

  <script type="text/javascript" language="javascript">
    function onAdd() {
      resetValue();
      pcAddCustomer.Show();
    }

    function onEdit(index) {
      lblErrorMessage.SetText('');
      gvCustomer.GetRowValues(index, 'Id;CustomerNo;Name;Phone;Fax;Email;Address', fillRowValue);
    }

    function onDelete(id) {
      if (confirm('Bạn có chắc là muốn xóa khách hàng này?'))
        gvCustomer.PerformCallback('Delete|' + id);
    }

    function onSave() {
      if (checkInput())
        gvCustomer.PerformCallback('Save|');
    }

    function onbtnSearch(s, e) {
      gvCustomer.PerformCallback('Search|');
    }

    function onCancel() {
      pcAddCustomer.Hide();
    }

    function resetValue() {
      document.getElementById('<%=hfCustomer.ClientID %>').value = '';
      txtName.SetText('');
      txtFax.SetText('');
      txtPhone.SetText('');
      txtEmail.SetText('');
      txtAddress.SetText('');
      lblErrorMessage.SetText('');
    }

    function checkInput() {
      var error = '';
      if (txtName.GetText() == '')
        error += '<BR> + ' + 'Tên khách hàng không được bỏ trống'
      if (error != '') {
        lblErrorMessage.SetText(error);
        return false;
      }
      return true;
    }

    function fillRowValue(values) {
      //Id;Name;Cmnd;Telephone;Email;Address
      document.getElementById('<%=hfCustomer.ClientID %>').value = values[0];
      txtName.SetText(values[2]);
      txtPhone.SetText(values[3]);
      txtFax.SetText(values[4]);
      txtEmail.SetText(values[5]);
      txtAddress.SetText(values[6]);

      pcAddCustomer.Show();
    }

    function ongvCustomer_EndCallback(s, e) {
      var error = s.cpInnerError.split('|');
      if (error[0] == 'Save') {
        if (error[1] != '')
          lblErrorMessage.SetText(error[1]);
        else {
          pcAddCustomer.Hide();
          alert('Cập nhật thành công');
        }
      }
      else if (error[0] != '') {
        alert(error[0]);
      }

    }
  </script>

</asp:Content>
